<?php
	session_start();
	echo"<link rel = 'stylesheet' type = 'text/css' href = 'friendshipsRequestsStyle.css'>";
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users");
	$inv=mysql_query("SELECT friendships.userID, friendships.id, users.FirstName, users.LastName, users.id, friendships.friendID FROM friendships JOIN users ON friendships.userID=users.id WHERE friendID={$_SESSION['JID']} AND confirmed=0");
	if (mysql_num_rows ($inv)==0)
	{
		echo "There are no new friend requests!";
	}
	else
	{
		while ($result=mysql_fetch_array($inv, MYSQL_NUM))
		{
			echo "<div class = 'friendshipRequestTabularThing'>".$result[2]." ".$result[3]." wants to be a friend with you! <br><button id=".$result[1]." class = 'confirmFriendshipButton'>Confirm</button><button id=".$result[0]." class = 'declineFriendshipButton'>Decline!</button></div>";
		}
	}
	echo"<script>
	$('.confirmFriendshipButton').click(function()
	{
		$('.confirmFriendshipButton').removeClass('focus');
		$(this).addClass('focus');
		var theId = $('.focus').attr('id');
		$.post('confirmFriendship.php', {idfr : theId}, function(data)
		{
			$('#newsDialogTitle').html('Friendship requests');
			$('#newsDialogHeadless').load('friendRequests.php');
		});
	});
	$('.declineFriendshipButton').click(function()
	{
		$('.declineFriendshipButton').removeClass('focus');
		$(this).addClass('focus');
		var theId = $('.focus').attr('id');
		var userId = ".$_SESSION['JID'].";
		$.post('delFriendship.php', {MyID : userId, frID : theId}, function(data)
		{	
			$('#newsDialogTitle').html('Friendship requests');
			$('#newsDialogHeadless').load('friendRequests.php');
		});
	});
	</script>";
?>






































